package test;

import org.dreamwork.jasmine2.events.EventException;
import org.dreamwork.jasmine2.web.controls.Page;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: seth
 * Date: 13-2-22
 * Time: 下午5:54
 */
public class RepeaterPage extends Page {
    protected List<Object> data;

    public RepeaterPage () {
        data = new ArrayList<Object> ();
        for (int i = 1; i <= 3; i ++) {
            String key = String.valueOf (i);
            Map<String, Object> map = new HashMap<String, Object> ();
            List<Object> list = new ArrayList<Object> ();
            map.put ("name", key);
            map.put ("value", list);
            for (int j = 1; j <= 3; j ++) {
                String key1 = key + '.' + j;
                Map<String, Object> m = new HashMap<String, Object> ();
                List<Object> l = new ArrayList<Object> ();
                m.put ("name", key1);
                m.put ("value", l);

                for (int k = 1; k <= 3; k ++) {
                    Map<String, Object> mm = new HashMap<String, Object> ();
                    mm.put ("name", key1 + '.' + k);
                    mm.put ("value", key1 + '.' + k);
                    l.add (mm);
                }
                list.add (m);
            }
            data.add (map);
        }
    }

    @Override
    public void onPageLoadCompleted (Page page) throws EventException {
        try {
            dataBind ();
        } catch (Throwable throwable) {
            throwable.printStackTrace ();
            throw new EventException (throwable);
        }
    }


}